//
//  MusicYue_V_TableViewCell.m
//  STL_ Animation
//
//  Created by 孙健 on 16/3/31.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "MusicYue_V_TableViewCell.h"


@interface MusicYue_V_TableViewCell ()

@end


@implementation MusicYue_V_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageViewLeft = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.labelTitle = [[UILabel alloc] initWithFrame:CGRectZero];
        self.artistName = [[UILabel alloc] initWithFrame:CGRectZero];
        self.totalViews = [[UILabel alloc] initWithFrame:CGRectZero];
        self.buttonSmall = [UIButton buttonWithType:UIButtonTypeSystem];
        
        
        self.labelTitle.font = [UIFont systemFontOfSize:13];
        self.artistName.font = [UIFont systemFontOfSize:12];
        self.totalViews.font = [UIFont systemFontOfSize:11];
        
        self.artistName.textColor = [UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1];
        self.totalViews.textColor = [UIColor grayColor];
        
        [self.contentView addSubview:self.imageViewLeft];
        [self.contentView addSubview:self.labelTitle];
        [self.contentView addSubview:self.artistName];
        [self.contentView addSubview:self.totalViews];
        [self.contentView addSubview:self.buttonSmall];
        
    }
    
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.imageViewLeft.frame = CGRectMake(0, 0, self.contentView.bounds.size.width/2 - 20, self.contentView.bounds.size.height);
    self.labelTitle.frame = CGRectMake(self.contentView.bounds.size.width/2 - 10, self.contentView.bounds.size.height/4, self.contentView.bounds.size.width/2 - 20, self.contentView.bounds.size.height/4);
    self.artistName.frame = CGRectMake(self.contentView.bounds.size.width/2 - 10, self.contentView.bounds.size.height/2, self.contentView.bounds.size.width/2 - 20, self.contentView.bounds.size.height/4);
    self.totalViews.frame = CGRectMake(self.contentView.bounds.size.width/2 - 10, self.contentView.bounds.size.height/4 * 3, self.contentView.bounds.size.width/2 - 20, self.contentView.bounds.size.height/4);
    self.buttonSmall.frame = CGRectMake(self.contentView.bounds.size.width - 40, self.contentView.bounds.size.height/3, 30, 30);
}

- (void)setMusicModel:(MusicYue_V_Model *)musicModel {
    
    _musicModel = musicModel;
    [self.imageViewLeft sd_setImageWithURL:[NSURL URLWithString:musicModel.posterPic]];
    NSString *string = [NSString stringWithFormat:@"播放次数:%@", musicModel.totalViews.stringValue];
    
    self.labelTitle.text = musicModel.title;
    self.artistName.text = musicModel.artistName;
    self.totalViews.text = string;
    [self.buttonSmall setImage:[[UIImage imageNamed:@"hui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.buttonSmall addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction:(UIButton *)button {
    self.block(self.count);
}


@end
